package cn.org.spring.wechar.config;

import cn.org.spring.wechar.interceptor.LoginUserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author： 谢辉
 * @date： 2021/5/10
 * @email: xieh_mail@163.com
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginUserInterceptor loginUserInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(loginUserInterceptor);
        System.out.println("loginUserInterceptor:" + loginUserInterceptor);
        registration.addPathPatterns("/**");
        registration.excludePathPatterns("/**/weChar",
                "/**/weChar/getCode",
                "/**/index",
                "/**/login",
                "/static/**",
                "/druid/*",
                "/favicon.ico",
                "/**/view/**",
                "/error",
                "/**/isWorker",
                "/common/**");
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
    }

}
